package cn.ming.wfchat.app.me.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Switch;

import butterknife.BindView;
import butterknife.OnClick;
import cn.ming.wfchat.R;
import cn.ming.wfchat.app.AppService;
import cn.ming.wfchat.kit.WfcBaseActivity;
import cn.wildfirechat.remote.ChatManager;

/**
 * @author luoming
 * created at 2020/9/7 3:15 PM
 * 修改解锁密码
 */
public class SetModifyUnlockActivity extends WfcBaseActivity {


    @BindView(R.id.swith)
    Switch swith;
    @BindView(R.id.ll_xiugai)
    LinearLayout llXiugai;
    private SharedPreferences sp;

    @Override
    protected int contentLayout() {
        return R.layout.activity_set_modify_unlock;
    }

    @Override
    protected void afterViews() {
        setTitle("解锁密码");
        sp = getSharedPreferences("config", Context.MODE_PRIVATE);
        swith.setChecked(sp.getBoolean("lockPasswordEnable", false));
        swith.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                lockPasswordEnable();
            }
        });
    }

    void lockPasswordEnable() {
        AppService.Instance().lockPasswordEnable(new AppService.SendCodeCallback() {
            @Override
            public void onUiSuccess() {
                sp.edit().putBoolean("lockPasswordEnable", !ChatManager.isLockPasswordEnable())
                        .apply();
            }

            @Override
            public void onUiFailure(String msg) {
                ChatManager.showToast(msg);
                swith.setChecked(!swith.isChecked());
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    //修改密码
    @OnClick(R.id.ll_xiugai)
    void setLlXiugai() {
        Intent intent = new Intent(SetModifyUnlockActivity.this, SetUnlockActivity.class);
        intent.putExtra("modify", true);
        startActivity(intent);
    }

}
